/*
 * hashring.h
 *
 *  Created on: 2012-4-1
 *      Author: zhanggx
 */
#ifndef GX_HASH_RING_H_
#define GX_HASH_RING_H_

#include "gx.h"

struct gx_hash_vnode_s {
	gx_hash_node_t* realnode;
	gx_string_t key;
};

struct gx_hash_node_s {
	gx_string_t key;
	void*		usr_data;

	//used only for load-balance mode
	gx_array_t* vnode_array;
};

struct gx_hashring_s {
	gx_rbtree_t* node_tree; //store vnodes in the ring

	gx_rbtree_t* node_count;
	gx_rbtree_t* vnode_count;
	int(*init_ring)(gx_hashring_t*);
	int(*copy_to_ring)(const gx_hashring_t* hashring, gx_hashring_t*);
	int(*add_node)(gx_hashring_t*, gx_string_t key, void *usr_data);
	int(*delete_node)(gx_hashring_t* ring, gx_string_t key);
	int(*select_node_for_key)(gx_hashring_t* ring, gx_hash_node_t* node, gx_string_t key);
	void(*destroy_ring)(gx_hashring_t*);
};

#endif
